<?php


namespace App\Http\observer;


use App\Http\service\XcxService;
use App\Jobs\CouponJob;
use App\Models\User;
use App\Models\Sys as SysModel;

class UserObserver
{
    public function created(User $user)
    {

        if ($user["invite_uid"]&&$user->id!=$user->invite_uid){
            $invite_get_draw=SysModel::getValue("invite_get_draw");
            User::where("id",$user["invite_uid"])->increment("draw_times",$invite_get_draw);
        }
        $scene="type=user_code&uid={$user->id}";
        $path=(new XcxService())->create_xcx_code($scene);
        CouponJob::dispatch($user);
        if($path){
            User::where("id",$user->id)->update(["qrcode"=>$path]);
        }
    }
}
